package com.atguigu.mall.ware.service.impl;

import cn.hutool.core.util.ObjectUtil;
import cn.hutool.core.util.StrUtil;
import com.atguigu.common.utils.PageUtils;
import com.atguigu.common.utils.Query;
import com.atguigu.mall.ware.dao.PurchaseDetailDao;
import com.atguigu.mall.ware.entity.PurchaseDetailEntity;
import com.atguigu.mall.ware.service.PurchaseDetailService;
import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.baomidou.mybatisplus.core.metadata.IPage;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import org.springframework.stereotype.Service;

import java.util.Map;


@Service("purchaseDetailService")
public class PurchaseDetailServiceImpl extends ServiceImpl<PurchaseDetailDao, PurchaseDetailEntity> implements PurchaseDetailService {

    @Override
    public PageUtils queryPage(Map<String, Object> params) {
//                status: 0,//状态
//                wareId: 1,//仓库id
        String status = (String) params.get("status");
        String wareId = (String) params.get("wareId");
        String key = (String) params.get("key");
        LambdaQueryWrapper<PurchaseDetailEntity> wrapper = new LambdaQueryWrapper<>();
        if (StrUtil.isNotBlank(key)){
            wrapper.and(w->w.eq(PurchaseDetailEntity::getPurchaseId,key).or()
                    .eq(PurchaseDetailEntity::getSkuId,key));
        }
        wrapper.like(ObjectUtil.isNotNull(status),PurchaseDetailEntity::getStatus,status);
        wrapper.like(ObjectUtil.isNotNull(wareId),PurchaseDetailEntity::getWareId,wareId);
        IPage<PurchaseDetailEntity> page = this.page(
                new Query<PurchaseDetailEntity>().getPage(params),
                wrapper
        );

        return new PageUtils(page);
    }

}